public class MyQueue {
    static class ListNode{
        private int val;
        ListNode prev;
        ListNode next;
        private ListNode(int val){
            this.val = val;
        }
    }
    private ListNode front;//队头
    private ListNode rear;//队尾
    private int usedSize;
    //头插法
    public void offer(int x){
        ListNode node = new ListNode(x);
        if (front == null){
            front = rear = node;
        }else {
            node.next = front;
            front.prev = node;
            front = node;
        }
        usedSize++;
    }





    //出队列
    public int poll() {
        if (front == null) {
            return -1;
        }
        int ret = front.val;
        if (front == rear) {
            front = null;
            rear = null;
            usedSize--;
            return ret;
        }
        front = front.next;
        front.prev = null;
        usedSize--;
        return ret;
    }






    public int peek(){
        if (front == null){
            return -1;
        }
        return front.val;
    }

    public int getUsedSize(){
        return usedSize;
    }

    public boolean isEmpty(){
        return usedSize == 0;
    }
}
